package grape.composite.service.businessdistrict.api;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import grape.common.service.trans.ITransService;
import grape.composite.service.businessdistrict.po.BusinessDistrict;
import grape.common.service.common.IBaseService;

/**
 * <p>
 * 商圈表 服务类
 * </p>
 *
 * @author yangwei
 * @since 2020-09-10
 */
public interface IBusinessDistrictService extends IBaseService<BusinessDistrict> , ITransService<String,String> {
    public static final String trans_business_district_name = "trans_business_district_name";
    /**
     * 判断编码是否已存在
     * @param code
     * @return
     */
    default boolean existCode(String code){
        assertParamNotEmpty(code,"code 不能为空");

        BusinessDistrict query = new BusinessDistrict();
        query.setCode(code);
        int r = count(Wrappers.query(query));
        return r > 0;
    }
    @Override
    default boolean support(String type){
        return isEqualAny(type,trans_business_district_name);
    }

    @Override
    default String trans(String type, String key){
        if (isStrEmpty(key)) {
            return null;
        }
        if (isEqual(type,trans_business_district_name)) {
            BusinessDistrict po = getById(key);
            if (po != null) {
                return po.getName();
            }
        }
        return null;
    }
}
